/**
 * Title: PermissionController.java
 * @author wujin
 * @date 2019年12月30日
 * @version 1.0
 */
package com.pm.controller.security;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.pm.common.Pages;
import com.pm.common.Response;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.security.Permission;
import com.pm.service.security.PermissionService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * Title: PermissionController
 * 
 * @author wujin
 * @date 2019年12月30日
 */
@Api(tags = "权限管理")
@UserLoginToken
@RestController
@RequestMapping("/permission")
public class PermissionController{
	@Autowired
	private PermissionService permissionService;

	@ApiOperation("新增接口")
	@PostMapping("/add")
	@ResponseBody
	@MyLog(value="新增权限信息")
	public Response<Integer> add(Permission permission) {
		Response<Integer> response = null;
		Integer result = permissionService.add(permission);
		if (result > 0) {
			response = new Response<>(ExpCodeState.add_data_success, result);
		} else {
			response = new Response<>(ExpCodeState.add_data_failed);
		}
		return response;
	}

	@ApiOperation("更新接口")
	@PostMapping("/update")
	@ResponseBody
	@MyLog(value="编辑权限信息")
	public Response<Integer> update(Permission permission) {
		Response<Integer> response = null;
		Integer result = permissionService.update(permission);
		if (result > 0) {
			response = new Response<>(ExpCodeState.update_data_success, result);
		} else {
			response = new Response<>(ExpCodeState.update_data_failed);
		}
		return response;
	}

	@ApiOperation("删除接口")
	@PostMapping("/remove")
	@ResponseBody
	@MyLog(value="删除权限信息")
	public Response<Integer> remove(Permission permission) {
		Response<Integer> response = null;
		Integer result = permissionService.remove(permission);
		if (result > 0) {
			response = new Response<>(ExpCodeState.remove_data_success, result);
		} else {
			response = new Response<>(ExpCodeState.remove_data_failed);
		}
		return response;
	}

	@ApiOperation("单个对象查询接口")
	@PostMapping("/load")
	@ResponseBody
	public Response<Permission> load(Permission permission) {
		Response<Permission> response = null;
		Permission result = permissionService.load(permission);
		response = new Response<Permission>(ExpCodeState.query_data_success, result);
		return response;
	}

	@ApiOperation("全部列表查询接口")
	@PostMapping("/getList")
	@ResponseBody
	public Response<List<Permission>> getList(Permission permission) {
		List<Permission> result = permissionService.getList(permission);
		Response<List<Permission>> res = new Response<List<Permission>>(ExpCodeState.query_data_success, result);
		return res;
	}

	@ApiOperation("分页查询接口")
	@PostMapping("/getListByPage/{pageNum}/{pageSize}")
	@ResponseBody
	@MyLog(value="查询权限信息")
	public Response<PageInfo<Permission>> getList(Permission permission, Pages page) {
		PageInfo<Permission> result = permissionService.getListByPage(permission, page);
		Response<PageInfo<Permission>> res = new Response<PageInfo<Permission>>(ExpCodeState.query_data_success, result);
		return res;
	}

	
}
